package com.alm.web.controller.alm.statisticalexport;

import com.alm.common.annotation.Log;
import com.alm.common.core.controller.BaseController;
import com.alm.common.core.domain.AjaxResult;
import com.alm.common.core.domain.entity.SysUser;
import com.alm.common.core.page.TableDataInfo;
import com.alm.common.enums.BusinessType;
import com.alm.common.utils.SecurityUtils;
import com.alm.handle.core.domain.entity.SysAreaInfo;
import com.alm.handle.core.domain.entity.SysDevLoginLog;
import com.alm.handle.core.domain.entity.rq.StatisticsStatementRQ;
import com.alm.handle.core.domain.entity.rs.StatisticsStatementRS;
import com.alm.handle.core.domain.entity.rs.StatisticsStatementSumRS;
import com.alm.handle.service.ISysAreaInfoService;
import com.alm.handle.service.ISysDevLoginLogService;
import com.alm.system.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/alm/dev/almstatisticsstatement")
public class AlmStatisticsStatementController extends BaseController {

    @Autowired
    private ISysMenuService menuService;

    @Autowired
    private ISysAreaInfoService areaInfoService;

    @Autowired
    private ISysDevLoginLogService devLoginLogService;


    @PostMapping("/getinfo")
    public AjaxResult getAreaList( StatisticsStatementRQ statementRQs) {
        StatisticsStatementSumRS sumRS=null;
        if(statementRQs.getEndTime()!=null){
            statementRQs.setEndTime(statementRQs.getEndTime()+23 * 60 * 60 + 59 * 60 + 59);
        }
        List<StatisticsStatementRS> areaInfos = areaInfoService.getStatisData(statementRQs.getAreaId(),
                statementRQs.getStartTime(),
                statementRQs.getEndTime());
        if(areaInfos!=null&&areaInfos.size()>0){
            sumRS=new StatisticsStatementSumRS();
            for(StatisticsStatementRS rs:areaInfos){
                sumRS.getSumDev().add(rs.getSumexDev());
                sumRS.getSumEnerty().add(rs.getSumEnerty());
                sumRS.getSumPower().add(rs.getSumPower());
                sumRS.getSumexDev().add(rs.getSumexDev());
                sumRS.getSumOnlineDev().add(rs.getSumOnlineDev());
                sumRS.getTimeData().add(rs.getData());
            }
        }
        return success(sumRS);
    }

}
